import { IColor } from "@/enum/shape.enum";
import { IType } from "@/interface/IShape";
import { BaseShape } from "./BaseShape";

/* 动态文本配置，设置整数和小数的样式 */
export interface DynamicTextConfig {
  /* 字体大小 */
  fontSize: number;
  color: string;
  /* 保留的小数位 */
  toFixed: number;
  /* 对齐，上标，下标 */
  align: "superscript" | "subscript" | "normal";
  /* 是否具有小数点 */
  includeDecimal: boolean;
  /* 是否显示小数位 */
  hasDecimal: boolean;
  format: string;
  prefix?: string;
  digits: number;
}
export class TextShape extends BaseShape {
  text: string;

  bgcolor: IColor;

  /* 字体大小 */
  fontSize: number;

  fontFamily: string;

  /* 转换成阿拉伯文 */
  arabic: boolean;

  /* 字体颜色 */
  textColor: IColor;

  /* 是否可编辑，初始化为true方便用户输入 */
  edit: boolean;

  /* 行高 */
  lineHeight: number;

  /* 超出隐藏 */
  overflow: boolean;

  /* 是否换行 */
  wrap: "break-spaces" | "normal" | "pre" | "pre-line" | "pre-wrap" | "nowrap";

  /* 是否加粗 */
  bold: boolean;

  /* 文本位置 */
  textPosition:
    | "flex-q"
    | "justify-center items-center"
    | "flex-w"
    | "flex-e"
    | "flex-a"
    | "justify-center items-center"
    | "flex-d"
    | "flex-z"
    | "flex-x"
    | "flex-c"
    | "";

  /* 装饰线 */
  decoration:
    | "dashed"
    | "dotted"
    | "line-through"
    | "overline"
    | "underline"
    | "wavy"
    | ""
    | "none";

  /* 倾斜 */
  fontStyle: "italic" | "normal" | "oblique";

  /* 垂直对齐 */
  verticalAlign: "baseline" | "bottom" | "middle" | "sub" | "text-bottom" | "top";

  /* 单词间距 */
  letterSpacing: number;

  /* 单词是否折断 */
  wordBreak: boolean;

  /* 单词的间距 */
  wordSpacing: number;

  constructor() {
    super();
    this.text = "TEXT";
    this.type = IType.TEXT;
    this.bgcolor = IColor.TRANSPARENT;
    this.fontSize = 12;
    this.textColor = IColor.BLACK;
    this.edit = false;
    this.lineHeight = 14;
    this.overflow = true;
    this.hasBorder = false;
    this.wrap = "normal";
    this.fontStyle = "normal";
    this.decoration = "";
    this.textPosition = "flex-q";
    this.bold = false;
    this.fontFamily = "Microsoft Yahei";
    this.verticalAlign = "baseline";
    this.wordBreak = false;
    this.letterSpacing = 0;
    this.wordSpacing = 0;
    this.arabic = false;
  }
}

/* 动态文本 */
export class DynamicText extends TextShape {
  /* 字段ID */
  fieldId: string;

  /* 字段编码 */
  fieldCode: string;

  format: boolean;

  fieldType: 0 | 1 | 2 ;

  decimal?: DynamicTextConfig;

  constructor() {
    const textFormat: DynamicTextConfig = {
      fontSize: 12,
      color: "",
      toFixed: 0,
      align: "normal",
      includeDecimal: true,
      hasDecimal: true,
      format: "",
      digits: 2
    };
    super();
    this.type = IType.DTEXT;
    this.fieldId = "";
    this.fieldCode = "";
    this.wrap = "nowrap";
    this.format = false;
    this.fieldType = 0;
    this.decimal = textFormat;
  }
}
